;
var user_edit_ops = {
    init: function () {
        this.eventBind()
    },
    eventBind: function () {
        $(".user_edit_wrap .save").click(function () {

            console.log('1111');

            let btn_target = $(this);

            // 防止重复点击
            if (btn_target.hasClass('disabled')) {
                common_ops.alert('正在处理，请稍稍');
                return
            }

            let nickname_target = $('.user_edit_wrap input[name=nickname]');
            let nickname = nickname_target.val();

            let email_target = $('.user_edit_wrap input[name=email]');
            let email = email_target.val();

            if ( !nickname || nickname.length < 2) {
                common_ops.tip('请输入符合规范的姓名', nickname_target);
                return false
            }

            if ( !email || email.length < 2) {
                common_ops.tip('请输入符合规范的邮箱', email_target);
                return false
            }

            btn_target.addClass("disabled");

            let data = {
                nickname: nickname,
                email: email
            };

            $.ajax({
                url: common_ops.buildUrl("/user/edit"),
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (res) {
                    btn_target.removeClass('disabled');
                    let callback = null;
                    if (res.code == 200) {
                        callback = function () {
                            window.location.href = common_ops.buildUrl('/');
                        }
                    }
                    common_ops.alert(res.msg, callback)
                }
            })

        })
    }
}

$(document).ready(function () {
    user_edit_ops.init()
})